package cn.e4j.modular.api.controller;

import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.modular.api.mapper.WXUserMapper;
import cn.e4j.modular.api.service.GwaService;
import cn.e4j.modular.api.util.ControllerSupport;
import cn.e4j.modular.system.entity.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by wenchuan on 2018/5/17.
 */
@RestController
@RequestMapping("api/wx/gwa")
public class GwaController extends ControllerSupport {

    @Autowired
    private GwaService gwaService;

    @Autowired
    private WXUserMapper wxUserMapper;


    /**
     * 获取交易单位列表 -- 编号、简称
     */
    @RequestMapping(value = "getGwablList")
    @ResponseBody
    public ResponseData getGwablList(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWABLENT", inDto.getString("ENT"));
        return new SuccessResponseData(gwaService.getGwablList(inDto));
    }


    /**
     * 获取当前登录者的信息 - gwaa
     */
    @RequestMapping(value = "getGwaUser")
    @ResponseBody
    public ResponseData getGwaUser(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser user = wapper.getSysUser();

        inDto.put("GWAAENT", inDto.getString("ENT"));
        inDto.put("GWAA001", user.getACCOUNT());
        inDto.put("GWAAACTI", "Y");

        return new SuccessResponseData(gwaService.getGwaUser(inDto));
    }

    /**
     * 修改用户的经度 纬度
     */
    @RequestMapping(value = "setLocation")
    @ResponseBody
    public ResponseData setLocation(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser user = wapper.getSysUser();

        inDto.put("GWAAENT", inDto.getString("ENT"));
        inDto.put("GWAAACTI", "Y");
        inDto.put("GWAA001", user.getACCOUNT());
        inDto.put("GWAAMODU", user.getID());
        wxUserMapper.updateByKeyActi(inDto);
        return SUCCESS;
    }


    /**
     * 获取所有用户的经度 纬度
     */
    @RequestMapping(value = "getLocations")
    @ResponseBody
    public ResponseData getLocations(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWAAENT", inDto.getString("ENT"));
        inDto.put("GWAAACTI", "Y");

        return new SuccessResponseData(gwaService.getLocations(inDto));
    }

    /**
     * 获取商机分类
     *
     * @return
     * @author wenchuan.li on 2018/06/14 14:13
     */
    @RequestMapping(value = "getSjfl")
    @ResponseBody
    public ResponseData getSjfl(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWAAENT", inDto.getString("ENT"));
        inDto.put("GWAAACTI", "Y");

        return new SuccessResponseData(gwaService.getSjfl(inDto));
    }

    /**
     * 根据区域（省）获取经销商
     *
     * @return
     * @author wenchuan.li on 2018/06/14 15:18
     */
    @RequestMapping(value = "getJxsBy025")
    @ResponseBody
    public ResponseData getJxsBy025(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto gwaDto = Dtos.newDto();
        gwaDto.put("GWAKENT", inDto.getString("ENT"));

        return new SuccessResponseData(gwaService.getJxsBy025(gwaDto));
    }

    /**
     * 获取商机阶段
     *
     * @return
     * @author wenchuan.li on 2018/06/14 15:03
     */
    @RequestMapping(value = "getSjjd")
    @ResponseBody
    public ResponseData getSjjd(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWAVENT", inDto.getString("ENT"));
        inDto.put("GWAVACTI", "Y");

        return new SuccessResponseData(gwaService.getSjjd(inDto));
    }

    /**
     * 获取角色分类列表
     *
     * @return
     * @author wenchuan.li on 2018/07/04 10:47
     */
    @RequestMapping(value = "getJs")
    @ResponseBody
    public ResponseData getJs(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWAWENT", inDto.getString("ENT"));
        inDto.put("GWAWACTI", "Y");

        return new SuccessResponseData(gwaService.getJs(inDto));
    }

    /**
     * 获取职位列表
     * @return
     * @author wenchuan.li on 2018/07/04 10:57
     */
    @RequestMapping(value = "getZw")
    @ResponseBody
    public ResponseData getZw(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWBDENT", inDto.getString("ENT"));
        inDto.put("GWBDACTI", "Y");

        return new SuccessResponseData(gwaService.getZw(inDto));
    }


    /**
     * 获取客户列表
     *
     * @return
     * @author wenchuan.li on 2018/07/10 13:53
     */
    @RequestMapping(value = "getGwakList")
    @ResponseBody
    public ResponseData getGwakList(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWAKENT", inDto.getString("ENT"));
        inDto.put("GWAKACTI", "Y");

        return new SuccessResponseData(gwaService.getGwakList(inDto));
    }

    /**
     * 获取经销商列表
     *
     * @return
     * @author wenchuan.li on 2018/07/10 13:53
     */
    @RequestMapping(value = "getGwakByFwzz")
    @ResponseBody
    public ResponseData getGwakByFwzz(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        inDto.put("GWAKENT", inDto.getString("ENT"));
        inDto.put("GWAKACTI", "Y");

        SysUser user = wapper.getSysUser();
        inDto.put("GWAA001", user.getACCOUNT());

        return new SuccessResponseData(gwaService.getGwakByFwzz(inDto));
    }

    /**
     * 获取关键评估项列表
     *
     * @return
     * @author wenchuan.li on 2018/07/12 15:08
     */
    @RequestMapping(value = "getGjpgx")
    @ResponseBody
    public ResponseData getGjpgx(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();

        inDto.put("GWBCENT", inDto.getString("ENT"));
        inDto.put("GWBCACTI", "Y");


        return new SuccessResponseData(gwaService.getGjpgx(inDto));
    }

    /**
     * 获取用户 by 客户idgwak001
     *
     * @return
     * @author wenchuan.li on 22018/07/17 16:33
     */
    @RequestMapping(value = "getGwakBygwak001")
    @ResponseBody
    public ResponseData getGwakBygwak001(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        inDto.put("GWAKENT", inDto.getString("ENT"));
        inDto.put("GWAKACTI", "Y");

        return new SuccessResponseData(gwaService.getGwakBygwak001(inDto));
    }

}
